package net.lanelife.casino.common.utils;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;


public class ArrayUtils extends org.apache.commons.lang.ArrayUtils {
	
	public static boolean duplicate(Object[] array) {
		for (int i = 0; i < array.length - 1; i++) {
			for (int j = i + 1; j < array.length; j++) {
				if (array[i].equals(array[j])) {
					return true;
				}
			}
		}
		return false;
	}
	
	public static boolean duplicate(Object[] one, Object[] two) {
		for (Object a : one) {
			for (Object b: two) {
				if (a.equals(b)) {
					return true;
				}
			}
		}
		return false;
	}
	
	public static Object[] intersect(Object[] one, Object[] two) {
		Set<Object> a = new HashSet<>(Arrays.asList(one));
		Set<Object> b = new HashSet<>(Arrays.asList(two));
		a.retainAll(b);
		return a.toArray();
	}
	
	public static String join(Object[] array, String str) {
		StringBuffer sb = new StringBuffer();
		for (Object element : array) {
			sb.append(element).append(str);
		}
		sb.delete(sb.length() - str.length(), sb.length());
		return sb.toString();
	}

}
